package top.yudoge.dogeeditor.llm.rewrite

/**
 * @author Yudoge
 * @since 2025/04/13
 *
 * RewriteCallback is a callback interface for the RewriteTask.
 */
interface RewriteCallback {

    fun onEvent(event: RewriteEvent)

    fun complete() {
        onEvent(RewriteEvent(RewriteEventType.Complete, null))
    }

    fun token(token: String) {
        onEvent(RewriteEvent(RewriteEventType.Token, token))
    }

    fun reasoning(reasoningForWhat: String) {
        onEvent(RewriteEvent(RewriteEventType.Reasoning, reasoningForWhat))
    }

    fun error(error: Throwable?) {
        onEvent(RewriteEvent(RewriteEventType.Error, error))
    }

}

data class RewriteEvent(
    val type: RewriteEventType,
    val data: Any?
)

enum class RewriteEventType {
    Token,      // There's new token generated by llm
    Reasoning,  // The llm is reasoning
    SQLSelfChecking, // Checking the generated SQL
    Error,      // Rewrite task failed with some error. (final state)
    Complete,   // Rewrite task successed. (final state)
    // The word `final state` means no more event will be sent.
}